package com.maksdu.LactiveMQ.produce;

import com.maksdu.LactiveMQ.domain.Message;

public class Producer {

	/**
	 * 消息预处理器
	 */
	private MessagePrepareHandler prepareHandler;
	private MessageHandler handler;
	private MessageNetWorker producerWorker;
	private MessageAfterHandler afterHandler;
	
	public Producer(MessageNetWorker producerWorker) {
		this.producerWorker = producerWorker;
	}
	
	public void send(Message message) {
		if(producerWorker == null) {
			return;
		}
		if(prepareHandler !=null) {
			//先序列化
			prepareHandler.serialize(message);
			//然后压缩
			prepareHandler.compress(message);
		}
		if(prepareHandler !=null) {
			handler.handle(message);
		}
		producerWorker.send(message);
		if(afterHandler !=null) {
			afterHandler.put(message);
		}
	}
}
